package cn.edu.scau.cmi.huxiantao.singleton;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Text;

public class GUIController implements Initializable{
	@FXML
	private TextField textField;
	@FXML
	private Text text;
	@FXML 
	private TextArea textArea;
	@FXML
	private ImageView imageView;
	
	private Chairman chairman;
	private int count=0;
	
	@FXML
	private void createChairman() {
		String name=textField.getText();
		chairman=Chairman.getInstance(name);
		count++;
	}
	@FXML
	private void validate() {
		if(chairman!=null)
			text.setText("创建次数="+count+
					"\nname="+chairman.getName()+"\ninstance="+chairman);
	}
	
	@FXML
	private void createTenMarshal() {
		String text="";
		if(Multipleton.getAllInstances().size()<10) {
			text=textArea.getText()+"创建成功\n";
		}else {
			text=textArea.getText()+"元帅数量已经到达10个，无法继续创建\n";
		}
		textArea.setText(text);
		
		Multipleton.addInstance("朱德");
		Multipleton.addInstance("彭德怀");
		Multipleton.addInstance("林彪");
		Multipleton.addInstance("刘伯承");
		Multipleton.addInstance("贺龙");
		Multipleton.addInstance("陈毅");
		Multipleton.addInstance("罗荣桓");
		Multipleton.addInstance("徐向前");
		Multipleton.addInstance("聂荣臻");
		Multipleton.addInstance("叶剑英");
		
		
		Multipleton.addInstance("毛泽东");
		
	}
	@FXML
	private void showTenMarshal() {
		String text="";
		text=textArea.getText()+"中国十大元帅:\n";
		
		List<Multipleton> list=Multipleton.getAllInstances();
		for(Multipleton multipleton:list) {
			text+=multipleton.getName()+"\n";
		}

		textArea.setText(text);
	}
	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {

		imageView.setImage(new Image("/cn/edu/scau/cmi/huxiantao/pic/pic.jpg"));
		
	}
}
